//
//  ViewController.m
//  YXKitOC
//
//  Created by 张鑫 on 2020/1/10.
//  Copyright © 2020 张鑫. All rights reserved.
//

#import "ViewController1.h"
#import "YXDatePicker.h"
#import "YXLocation.h"
#import "TestSegmentMenuMainVC.h"
#import "JXCategoryTitleView.h"
#import "JXCategoryIndicatorLineView.h"
#import "YXMenuFilterManager.h"
#import "YXKitOC.h"
#import "UIScrollView+YXRefresh.h"
#import "YXWebVC.h"
#import "YXCollectionViewVC.h"
#import "YXKitOC-Swift.h"
#import "YXDatePickerVC.h"

@interface ViewController1 () <UITableViewDelegate, UITableViewDataSource> {
    NSString *_test1;
}

@property (nonatomic, strong) UITableView *tableView; /**< 列表 */
@property (nonatomic, strong) NSArray *listArray; /**< 列表数据源 */

@end

@implementation ViewController1

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"功能代码示例";
    self.view.backgroundColor = YX_WhiteColor();
    [self.view addSubview:self.tableView];
    
    self.listArray = @[ @"01 时间选择器示例", @"02 定位经纬度示例", @"03 头条菜单示例", @"04 筛选菜单-列表-无数据页面示例", @"05 浏览器示例", @"06 YXCollectionView示例", @"07 YXTextField-倒计时按钮示例", @"08 YXMaskAlertView示例-图片占位图示例", @"09 OCR的VIN码识别", @"10 Swift类（调试用）"];
    [self.tableView reloadData];
    
    [self.tableView yx_beginRefreshing];
    
    #warning 张鑫测试 原理题1
    
    _test1 = @"bbq";
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    [self.view addSubview:btn];
    YX_WeakSelf
    [btn yx_addEventBlock:^(id  _Nonnull sender) {
//        YX_StrongSelf
        NSLog(@"😃😃");
        NSLog(@"%@ \n\n", _test1);
    }];
    
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:@"UITableViewCell"];
    }
    
    cell.textLabel.text = self.listArray[indexPath.row];
    NSRange range = [cell.textLabel.text rangeOfString:@"示例"];
    [cell.textLabel yx_setTextColor:YX_Color16(0x999999) font:YX_Font14() range:range];
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *title = self.listArray[indexPath.row];
    UIViewController *vc = nil;
    
    if ([title hasPrefix:@"01 时间选择器"]) {
        vc = [[YXDatePickerVC alloc] init];
    } else if ([title hasPrefix:@"02 定位经纬度"]) {
        YX_HUDShow();
        [YXLocation shared].isShowAlertAuthorization = NO;
        [[YXLocation shared] startWithSuccessBlock:^(CLLocationCoordinate2D locationCoordinate2D) {
            YX_HUDHide();
            YX_HUDShowMessage([NSString stringWithFormat:@"经度%@\n纬度%@", @(locationCoordinate2D.longitude), @(locationCoordinate2D.latitude)]);
        } errorBlock:^(NSError * _Nonnull error) {
            YX_HUDHide();
            YX_HUDShowMessage(error.domain);
        }];
    } else if ([title hasPrefix:@"03 头条菜单"]) {
        TestSegmentMenuMainVC *temp_vc = [[TestSegmentMenuMainVC alloc] init];
        temp_vc.title = @"分段菜单";
        temp_vc.hidesBottomBarWhenPushed = YES;
        JXCategoryTitleView *titleCategoryView = (JXCategoryTitleView *)temp_vc.categoryView;
        titleCategoryView.titleSelectedColor = [UIColor blueColor];
        titleCategoryView.backgroundColor = [UIColor whiteColor];
        temp_vc.isNeedIndicatorPositionChangeItem = YES;
        titleCategoryView.titleColorGradientEnabled = YES;
        JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
        lineView.indicatorWidth = JXCategoryViewAutomaticDimension;
        lineView.indicatorColor = [UIColor blueColor];
        //可以试试宽度补偿
        //        lineView.indicatorWidthIncrement = 10;
        titleCategoryView.indicators = @[lineView];
        vc = temp_vc;
    } else if ([title hasPrefix:@"04 筛选菜单"]) {
        vc = [[NSClassFromString(@"MenuFilterManagerDemoVC") alloc] init];
    } else if ([title hasPrefix:@"05 浏览器"]) {
        YXWebVC *temp_vc = [[YXWebVC alloc] init];
        temp_vc.url = [NSURL URLWithString:@"https://www.baidu.com"];
        temp_vc.cookie = @{@"user": @"zhxin", @"age": @"18"};
        vc = temp_vc;
    }
//    else if ([title hasPrefix:@"0 YXTableView"]) {
//        vc = [[NSClassFromString(@"YXTableViewVC") alloc] init];
//    }
    else if ([title hasPrefix:@"06 YXCollectionView"]) {
        vc = [[YXCollectionViewVC alloc] init];
    } else if ([title hasPrefix:@"07 YXTextField"]) {
        vc = [[NSClassFromString(@"YXTextFieldVC") alloc] init];
    } else if ([title hasPrefix:@"08 YXMaskAlertView"]) {
        vc = [[NSClassFromString(@"YXMaskAlertViewVC") alloc] init];
    } else if ([title hasPrefix:@"09 OCR的VIN码识别"]) {
//        vc = [[NSClassFromString(@"YXVinOCRDemoVC") alloc] init];
    } else if ([title hasPrefix:@"10 Swift"]) {
        vc = [[SwiftTestVC alloc] init];
    }
    
    if (vc) {
        vc.hidesBottomBarWhenPushed = YES;
        vc.title = title;
        [self.navigationController yx_pushViewController:vc];
    }
}

#pragma mark - Getter

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, YX_SafeArea_Top(), self.view.width, self.view.height - YX_SafeArea_Top() - self.tabBarController.tabBar.height)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

@end
